/****************** 基本存储 操作 ******************/
var set = function(key, val) {
  wx.setStorage({
    key: key,
    data: val
  });
};

var get = function(key) {
  try {
    var value = wx.getStorageSync(key);
    if (value) {
      return value;
    }
  } catch (e) {
    return {};
  }
};
var remove = function(key) {
  wx.removeStorage({
    key: key,
    success(res) {
      console.log("删除本地缓存___" + key);
    }
  });
};

/****************** 用于保存当前用户相关信息 val 新增属性，或者修改原属性 ******************/
var setCurrentUser = function(val) {
  var user = this.get("wxUserInfo");
  var obj = { ...user, ...val };
  this.set("wxUserInfo", obj);
};
var getCurrentUser = function() {
  return this.get("wxUserInfo");
};
var removeCurrentUserKey = function(key) {
  var user = this.get("wxUserInfo");
  delete user[key];
  this.set("wxUserInfo", user);
};

module.exports = {
  set,
  get,
  remove,
  setCurrentUser,
  getCurrentUser,
  removeCurrentUserKey
};
